import type { App } from "vue";

import MButton from "./components/button";
import MCoinAvatar from "./components/coin-avatar";
import MCopyAble from "./components/copy-able";
import MCell from "./components/cell";
import MEmpty from "./components/empty";
import MPagination from "./components/pagination";
import MPaginationA from "./components/pagination-a";
import MSkeleton from "./components/skeleton";

import { MCountLine, MCountLineItem } from "./components/count-line";
import MPopover from "./components/popover";
import MConfigProvider from "./components/config-provider";
import {
  Language,
  LocaleInjectionKey,
  localeProviderMaker,
} from "./hooks/useLocale";
import useCreateAPI from "./hooks/useCreateAPI";
import zh from "./hooks/useLocale/zh";
import en from "./hooks/useLocale/en";
import { messageA, MMessageA } from "./components/message";
const components = [
  MButton,
  MCoinAvatar,
  MCopyAble,
  MCell,
  MEmpty,
  MPagination,
  MPaginationA,
  MSkeleton,
  MCountLine,
  MCountLineItem,
  MPopover,
  MMessageA,
];
components.forEach((component) => {
  component.install = function (app: App) {
    app.component(component.name, component);
  };
});

interface installOpts {
  locale?: Language;
}

const install = (app: App, opts: installOpts = {}): void => {
  components.forEach((component) => {
    app.component(component.name, component);
  });

  if (opts.locale) {
    const localeProvides = localeProviderMaker(opts.locale);
    app.provide(LocaleInjectionKey, localeProvides);
  }
};

export {
  MButton,
  MCoinAvatar,
  MCopyAble,
  MCell,
  MEmpty,
  MPagination,
  MPaginationA,
  MSkeleton,
  MCountLine,
  MCountLineItem,
  MConfigProvider,
  useCreateAPI,
  MMessageA,
  messageA,
  zh,
  en,
};

export default {
  install,
};
